//package com.fingard.dsp.bank.directbank.citi01;
//
//import com.fingard.constant.Format;
//import com.fingard.dsp.bank.directbank.FailCode;
//import com.fingard.dsp.bank.directbank.PaymentState;
//import com.fingard.dsp.bank.directbank.bankInterface.ISinglePay;
//import com.fingard.dsp.bank.directbank.cmb01.CMB01Header;
//import com.fingard.dsp.bank.reqrespobj.foreigncurrsingle.ReqForeignCurrSingle;
//import com.fingard.dsp.bank.reqrespobj.foreigncurrsingle.RetAtsForeignCurrSingle;
//import com.fingard.dsp.bank.reqrespobj.foreigncurrsingle.detail.RetAtsForeignCurrPayDetail;
//import com.fingard.dsp.bank.reqrespobj.single.*;
//import com.fingard.dsp.bank.reqrespobj.single.detail.RetAtsSglDetail;
//import com.fingard.net.ConnState;
//import com.fingard.text.StringHelper;
//import com.fingard.xml.XmlTextReader;
//import com.fingard.xml.XmlTextWriter;
//
//import java.io.File;
//import java.util.*;
//
//import static com.fingard.io.FileHelper.readToString;
//
//public class CITI01SinglePay extends CITI01Base implements ISinglePay {
//
//    //单笔支付，不需采用流处理方式
//    public RetAtsSingle d_1908_SglPay(ReqSingle p_req1908) throws Exception {
//        //返回ATS的对象
//        RetAtsSingle retAts = new RetAtsSingle(p_req1908.reqHeader);
//        RetAtsSglDetail tmpRetDetail;
//        tmpRetDetail = foreignPayForHK(p_req1908);
//
//        retAts.writeRetDetail(tmpRetDetail);
//        return retAts;
//    }
//
//    /**
//     * 花旗国内支付
//     * */
//    public RetAtsSglDetail foreignPayForHK(ReqSingle reqForeignCurrSingle) throws Exception{
//        RetAtsSglDetail tmpRetAtsDetail = new RetAtsSglDetail();
//        tmpRetAtsDetail.respCode = "";
//        if(tmpRetAtsDetail.respCode.length() == 0) {
//            XmlTextWriter xmlWriter = new XmlTextWriter();
//            writeCommonHeader(xmlWriter);
//
//            writeFileContentCN(xmlWriter,reqForeignCurrSingle);
//
//                String[] tmpStrRet = sendToBank(xmlWriter.toXmlString(),"1908");//发送银行
//                if (tmpStrRet[0].length() == 0) {
//                    StringBuilder tmpSbMsg = new StringBuilder();
//                    //解析银行返回
//                    XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
//                    if (tmpBkReader != null) {
//                        String tmpRetCode = tmpBkReader.getFirstText("/Document/CstmrPmtStsRpt/OrgnlPmtInfAndSts/TxInfAndSts/TxSts");
//                        if (checkStatus(tmpRetCode) == 1) {
//                            tmpRetAtsDetail.respCode = "0";
//                            tmpRetAtsDetail.reqSeqID = reqForeignCurrSingle.singleDetail.askNumber;
//                            tmpRetAtsDetail.transState = "0000";
//                            tmpRetAtsDetail.payInfoCode = "0000";
//                            tmpRetAtsDetail.respInfo = "交易处理中";
//                        } else if(checkStatus(tmpRetCode) == 2){
//                            tmpRetAtsDetail.respCode = "-1";
//                            tmpRetAtsDetail.respInfo = "交易失败";
//                        } else if(checkStatus(tmpRetCode) == 3){
//                            tmpRetAtsDetail.respCode = "0";
//                            tmpRetAtsDetail.reqSeqID = reqForeignCurrSingle.singleDetail.askNumber;
//                            tmpRetAtsDetail.transState = "0000";
//                            tmpRetAtsDetail.payInfoCode = "0000";
//                            tmpRetAtsDetail.respInfo = "交易成功";
//                        } else{
//                            tmpRetAtsDetail.respCode = "-1";
//                            tmpRetAtsDetail.respInfo = "交易状态未知";
//                        }
//                    } else {
//                        tmpRetAtsDetail.respCode = "-1";
//                        tmpRetAtsDetail.respInfo = tmpSbMsg.toString();
//                    }
//                }else{
//                    tmpRetAtsDetail.respCode = "-1";
//                    tmpRetAtsDetail.respInfo = "交易失败";
//                }
//        }
//        return tmpRetAtsDetail;
//    }
//
//    //190801 付款
//    private RetAtsSglDetail d_190801(ReqSingle p_req1908) throws Exception {
//
//        RetAtsSglDetail retDetail = new RetAtsSglDetail();
//        CMB01Header tmpBnkHeader = new CMB01Header();
//        tmpBnkHeader.FUNNAM = "NTIBCOPR";
//        XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
//        xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
//        xmlWriter.writeStartElementByAttr("Document","xmlns:xsi");
//        xmlWriter.writeStartElement("CstmrCdtTrfInitn"); //顾客借贷交易开始
//        xmlWriter.writeStartElement("GrpHdr");
//        xmlWriter.writeElementString("MsgId",p_req1908.reqHeader.reqSeqID);//消息ID
//        xmlWriter.writeElementString("CreDtTm",Format.DateTime2Format.format(new Date()));
//        xmlWriter.writeStartElement("InitgPty"); // 开始组
//        xmlWriter.writeStartElement("Id");
//        xmlWriter.writeStartElement("OrgId"); //机构ID
//        xmlWriter.writeElementString("BICOrBEI",bankFront.org);
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("OrgnlGrpInfAndSts");
//        xmlWriter.writeElementString("OrgnlMsgId","GBP161111000001");
//        xmlWriter.writeElementString("OrgnlMsgNmId","pain.001.001.03");
//        xmlWriter.writeElementString("OrgnlCreDtTm",Format.DateTime2Format.format(new Date()));
//        xmlWriter.writeElementString("OrgnlNbOfTxs","1");
//        xmlWriter.writeStartElement("NbOfTxsPerSts");
//        xmlWriter.writeElementString("DtldNbOfTxs","1");
//        xmlWriter.writeElementString("DtldSts","ACCP");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("OrgnlPmtInfAndSts");
//        xmlWriter.writeElementString("OrgnlPmtInfId","98765432 Fund Transfer Domestic");
//        xmlWriter.writeStartElement("TxInfAndSts");
//        xmlWriter.writeElementString("OrgnlEndToEndId","ABC1234");
//        xmlWriter.writeElementString("TxSts","ACCP");
//        xmlWriter.writeStartElement("StsRsnInf");
//        xmlWriter.writeStartElement("Orgtr");
//        xmlWriter.writeElementString("Nm","CITIFILE");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeElementString("AddtlInf","/00000000/Payment Accepted for Submission");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeElementString("AcctSvcrRef","06005543500000001");
//        xmlWriter.writeStartElement("OrgnlTxRef");
//        xmlWriter.writeStartElement("Amt");
//        xmlWriter.writeElementAttribute("nstdAmt",p_req1908.singleDetail.payAmount,"Ccy","USD");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeElementString("ReqdExctnDt",Format.Date10Format.format(new Date()));
//        xmlWriter.writeStartElement("PmtTpInf");
//        xmlWriter.writeStartElement("SvcLvl");
//        xmlWriter.writeElementString("Cd","URGP");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("LclInstrm");
//        xmlWriter.writeElementString("Prtry","392");//所有权、归属
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("LclInstrm");
//        xmlWriter.writeElementString("Prtry","392");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeElementString("PmtMtd","TRF");//支付方法
//        xmlWriter.writeStartElement("RmtInf"); //支付信息
//        xmlWriter.writeElementString("Ustrd","TR002638"); //无规则
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("Dbtr"); //借方
//        xmlWriter.writeElementString("Nm",p_req1908.singleDetail.payName); //名称
//        xmlWriter.writeStartElement("PstlAdr"); //通讯地址
//        xmlWriter.writeElementString("Ctry","GB");//国家
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("DbtrAcct");//收借方账号
//        xmlWriter.writeStartElement("Id");
//        xmlWriter.writeStartElement("Othr");
//        xmlWriter.writeElementString("Id",p_req1908.singleDetail.payAct);
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("Tp");
//        xmlWriter.writeElementString("Prtry","CACC");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("DbtrAgt"); //收借方代理
//        xmlWriter.writeStartElement("FinInstnId"); //金融机构ID
//        xmlWriter.writeElementString("BIC","CITIGB2L"); //银行识别码
//        xmlWriter.writeStartElement("ClrSysMmbId"); //清算系统中标识成员
//        xmlWriter.writeElementString("MmbId","CITIGB2LAXXX"); //清算系统中标识成员ID
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("PstlAdr"); //通讯地址
//        xmlWriter.writeElementString("Ctry","GB"); //国家
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("BrnchId"); //分支机构标识
//        xmlWriter.writeElementString("Id","600");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("CdtrAgt"); //信用代理人
//        xmlWriter.writeStartElement("FinInstnId"); //金融机构的唯一和明确标识
//        xmlWriter.writeElementString("BIC","CITIGB2L");//银行识别码
//        xmlWriter.writeStartElement("ClrSysMmbId");
//        xmlWriter.writeElementString("MmbId","185008");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("BrnchId");
//        xmlWriter.writeElementString("Nm","CITIBANK(ISO)");
//        xmlWriter.writeStartElement("PstlAdr");
//        xmlWriter.writeElementString("Ctry","GB");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("Cdtr");//借货人
//        xmlWriter.writeElementString("Nm",p_req1908.singleDetail.recName);
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("CdtrAcct");
//        xmlWriter.writeStartElement("Id");
//        xmlWriter.writeElementString("IBAN",p_req1908.singleDetail.recAct); //账号
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartElement("Tp");
//        xmlWriter.writeElementString("Prtry","CACC");
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeEndDocument();
//        String[] tmpStrRet = sendToBank(xmlWriter.toXmlString(),"1908");//发送银行
//        if (tmpStrRet[0].length() == 0) {
//            StringBuilder tmpSbMsg = new StringBuilder();
//            //解析银行返回
//            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
//            if (tmpBkReader != null) {
//                String tmpRetCode = tmpBkReader.getFirstText("/Document/CstmrPmtStsRpt/OrgnlPmtInfAndSts/TxInfAndSts/OrgnlTxRef/CdtrAcct/Id/IBAN");
//                if (!StringHelper.isNullOrEmpty(tmpRetCode)) {
//                        retDetail.respCode = "0";
//                        retDetail.transState = "0";
//                        retDetail.reqSeqID = p_req1908.singleDetail.askNumber;
//                        retDetail.payInfoCode = "0";
//                        retDetail.respInfo = "交易处理中";
//                } else {
//                    retDetail.respCode = "-1";
//                    retDetail.respInfo = "交易失败";
//                }
//            } else {
//                retDetail.respCode = "-1";
//                retDetail.respInfo = tmpSbMsg.toString();
//            }
//        } else if (tmpStrRet[0].equals(ConnState.FAIL) || tmpStrRet[0].equals(FailCode.E9981)) {
//            retDetail.respCode = "0";
//            retDetail.respInfo = tmpStrRet[1];
//            retDetail.reqSeqID = p_req1908.singleDetail.askNumber;
//            retDetail.transState = PaymentState.FAIL_Payment;
//            retDetail.payInfoCode = tmpStrRet[0];
//        } else {
//            retDetail.respCode = "-1";
//            retDetail.respInfo = tmpStrRet[1];
//        }
//        return retDetail;
//    }
//
//    private void writeFileContentCN(XmlTextWriter xmlWriter, ReqSingle reqForeignCurrSingle) throws Exception {
//        xmlWriter.writeStartElement("GrpHdr");
//        xmlWriter.writeElementStringNotNull("MsgId", reqForeignCurrSingle.singleDetail.askNumber);
//        String currency = convertCurToBank(reqForeignCurrSingle.singleDetail.payCur);
//        String date = reqForeignCurrSingle.singleDetail.payDate + "T" + reqForeignCurrSingle.singleDetail.payTime;
//        xmlWriter.writeElementStringNotNull("CreDtTm", date);
//        xmlWriter.writeElementStringNotNull("NbOfTxs", "1");
//        xmlWriter.writeStartElement("InitgPty");
//        xmlWriter.writeElementStringNotNull("Nm", reqForeignCurrSingle.singleDetail.payName);
//        xmlWriter.writeEndElement();
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("PmtInf");
//        //流水号
//        xmlWriter.writeElementStringNotNull("PmtInfId", reqForeignCurrSingle.singleDetail.askNumber);
//        xmlWriter.writeElementStringNotNull("PmtMtd", "TRF");
//        xmlWriter.writeStartElement("PmtTpInf");
//        xmlWriter.writeStartElement("SvcLvl");
//        xmlWriter.writeElementStringNotNull("Cd", "URGP");
//        xmlWriter.writeEndElement();
//        xmlWriter.writeEndElement();
//        xmlWriter.writeElementStringNotNull("ReqdExctnDt", reqForeignCurrSingle.singleDetail.payDate);
//        xmlWriter.writeStartElement("Dbtr");
//        xmlWriter.writeElementStringNotNull("Nm", reqForeignCurrSingle.singleDetail.payName);
//        xmlWriter.writeStartElement("PstlAdr");
//        xmlWriter.writeElementStringNotNull("AdrLine", "TEST ORDERING PARTY ADDRESS 1");
//        xmlWriter.writeEndElement();
//
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("DbtrAcct");
//        xmlWriter.writeStartElement("Id");
//        xmlWriter.writeStartElement("Othr");
//        xmlWriter.writeElementStringNotNull("Id", reqForeignCurrSingle.singleDetail.payAct);
//        xmlWriter.writeEndElement();
//        xmlWriter.writeEndElement();
//        xmlWriter.writeElementStringNotNull("Ccy", currency);
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("DbtrAgt");
//        xmlWriter.writeStartElement("FinInstnId");
//        xmlWriter.writeElementStringNotNull("BIC", "CITICNSXSZN");
//        xmlWriter.writeStartElement("PstlAdr");
//        xmlWriter.writeElementStringNotNull("Ctry", "CN");
//        xmlWriter.writeEndElement();
//        xmlWriter.writeEndElement();
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("CdtTrfTxInf");
//        xmlWriter.writeStartElement("PmtId");
//        xmlWriter.writeElementStringNotNull("InstrId", reqForeignCurrSingle.singleDetail.askNumber + "1");
//
//        xmlWriter.writeElementStringNotNull("EndToEndId", reqForeignCurrSingle.singleDetail.askNumber);
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("Amt");
//        xmlWriter.writeElementAttribute("InstdAmt",reqForeignCurrSingle.singleDetail.payAmount,"Ccy",currency);
//        xmlWriter.writeEndElement();
//        xmlWriter.writeElementStringNotNull("ChrgBr", FeeBearer(reqForeignCurrSingle.singleDetail.costMode));
//        xmlWriter.writeStartElement("CdtrAgt");
//        xmlWriter.writeStartElement("FinInstnId");
//        xmlWriter.writeStartElement("ClrSysMmbId");
//        xmlWriter.writeElementStringNotNull("MmbId", reqForeignCurrSingle.singleDetail.cnapsCode);
//        xmlWriter.writeEndElement();
//        xmlWriter.writeElementStringNotNull("Nm",reqForeignCurrSingle.singleDetail.recBankName);
//        xmlWriter.writeStartElement("PstlAdr");
//        xmlWriter.writeElementStringNotNull("Ctry", "CN");
//        xmlWriter.writeEndElement();
//        xmlWriter.writeEndElement();
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("Cdtr");
//        xmlWriter.writeElementStringNotNull("Nm", reqForeignCurrSingle.singleDetail.recName);
//        xmlWriter.writeStartElement("PstlAdr");
//        xmlWriter.writeElementStringNotNull("AdrLine", "TEST");
//        xmlWriter.writeEndElement();
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("CdtrAcct");
//        xmlWriter.writeStartElement("Id");
//        xmlWriter.writeStartElement("Othr");
//        xmlWriter.writeElementStringNotNull("Id", reqForeignCurrSingle.singleDetail.recAct);
//        xmlWriter.writeEndElement();
//        xmlWriter.writeEndElement();
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("RmtInf");
//        String isFast = reqForeignCurrSingle.singleDetail.paySpd;
//        xmlWriter.writeElementStringNotNull("Ustrd", reqForeignCurrSingle.singleDetail.memo);
//
//        /*
//        if(isFast!=null && isFast.equals("1")){
//           xmlWriter.writeElementStringNotNull("Ustrd", "/IDTP/BBAN");//目前银行反馈不支持国内加急
//        }else {
//            xmlWriter.writeElementStringNotNull("Ustrd", reqForeignCurrSingle.singleDetail.memo);
//        }*/
//        xmlWriter.writeEndDocument();
//        xmlWriter.writeStartDocByDeclaration("\r\n"+"</Document>");
//    }
//
//
//
//    public RetAtsSingle d_1944_QrySglPay(ReqQrySingle p_req1944) throws Exception {
//
//                return d_1944_QrySglPayNew(p_req1944);
//
//    }
//
//    @Override
//    public RetAtsSingleBat d_1908BAT_SglBatPay(ReqSingleBat p_req1908BAT) throws Exception {
//        return null;
//    }
//
//    @Override
//    public RetAtsSingleBat d_1944BAT_QrySglBatPay(ReqQrySingleBat p_req1944BAT) throws Exception {
//        return null;
//    }
//
//
//    public RetAtsSingle d_1944_QrySglPayNew(ReqQrySingle p_req1944) throws Exception {
//        //返回ATS的对象
//        RetAtsSingle retAts = new RetAtsSingle(p_req1944.reqHeader);
//        RetAtsSglDetail detail = new RetAtsSglDetail();
//        detail.reqSeqID =  p_req1944.askNumber;
//            XmlTextWriter xmlWriter = new XmlTextWriter();
//            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
//            xmlWriter.writeElementAttribute("paymentInquiryRequest", "xmlns", "http://com.citi.citiconnect/services/types/inquiries/payment/v1");
//            xmlWriter.writeElementString("EndToEndId",detail.reqSeqID);
//            xmlWriter.writeEndDocument();
//            String[] tmpRetBkStr = sendToBankForStatus(xmlWriter.toXmlString(),detail.reqSeqID);
//            if (tmpRetBkStr[0].length() == 0) {
//                StringBuilder tmpSbMsg = new StringBuilder();
//                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpRetBkStr[1], tmpSbMsg);
//                if (tmpBkReader != null) {
//                    String tmpRetCode = tmpBkReader.getFirstText("/Document/CstmrPmtStsRpt/OrgnlGrpInfAndSts/OrgnlMsgId");
//                    if (!com.fingard.text.StringHelper.isNullOrEmpty(tmpRetCode)) {
//
//                        String repCode = tmpBkReader.getFirstText("/Document/CstmrPmtStsRpt/OrgnlPmtInfAndSts/TxInfAndSts/TxSts");
//                        detail.respCode = "0";
//                        detail.respInfo = tmpBkReader.getFirstText("/Message/Body/ErrMsg");
//                        if(checkStatus(repCode) == 1){
//                            detail.respInfo = "交易处理中";
//                        }
//                        if(checkStatus(repCode) == 2){
//                            detail.respInfo = "交易失败:" + tmpBkReader.getFirstText("/Document/CstmrPmtStsRpt/OrgnlPmtInfAndSts/TxInfAndSts/StsRsnInf/AddtlInf");
//                        }
//                        if(checkStatus(repCode) == 3){
//                            detail.respInfo = "交易成功";
//                        }
//                        if(checkStatus(repCode) == 0){
//                            detail.respInfo = "未知状态";
//                        }
//                        detail.transState = "190801" + checkStatus(repCode);
//                        detail.payInfoCode = detail.transState;
//                    } else {
//                        detail.respCode = "-1";
//                        detail.respInfo = "请求失败";
//                    }
//                } else {
//                    detail.respCode = "-1";
//                    detail.respInfo = tmpSbMsg.toString();
//                }
//            } else {
//                detail.respCode = "-1";
//                detail.respInfo = tmpRetBkStr[1];
//            }
//
//        retAts.writeRetDetail(detail);
//        return retAts;
//    }
//
//}
//
